package com.travel.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.classic.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.travel.base.impl.BaseDaoImpl;
import com.travel.bean.Order;
import com.travel.dao.OrderDao;
@Repository("orderDaoImpl")
public class OrderDaoImpl extends BaseDaoImpl<Order> implements OrderDao {

	/**
	 * 
	 * 按条件分页查询order
	 * @param order
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public List<Order> getOrdersByPage(Map map ,Integer pageNum,Integer pageSize){
		DetachedCriteria dc = DetachedCriteria.forClass(Order.class);
		if(map!=null){
			dc.add(Restrictions.allEq(map));
		}
		List<Order> orders=(List<Order>) this.hibernateTemplate.findByCriteria(dc, (pageNum-1)*pageSize, pageSize);
		return orders;
	}
	
	public Integer getCountByPage(Map map){

		DetachedCriteria dc = DetachedCriteria.forClass(Order.class);
		if(map!=null){
			dc.add(Restrictions.allEq(map));
		}
		dc.setProjection(Projections.rowCount());
		List count=this.hibernateTemplate.findByCriteria(dc);
		return ((Long)count.get(0)).intValue();
	}
}
